//#define __FORCE_TRACE__
//#define __FORCE_DEBUG__
//#define __FORCE_INFO__
#define THIS_FILE "tyr_menu\fn_keyDown.sqf"
#include <core_macros.h>

TRACE_1("Start",_this);
TMFPROFILERSTART;

private["_handled", "_ctrl", "_dikCode", "_shift", "_ctrlKey", "_alt"];
_ctrl = _this select 0;
_dikCode = _this select 1;
_shift = _this select 2;
_ctrlKey = _this select 3;
_alt = _this select 4;
_handled = false;

if (_dikCode in actionKeys "TeamSwitch") then {
	TRACE_1("Found",ARR_2(actionKeys "TeamSwitch", GVAR(ButtonUp)));
	if ((alive player) 
		&& {!dialog} 
		&& {!visibleMap} 
		&& {!(player getVariable ["xr_pluncon", false])} 
		&& {!(player getVariable ["d_isinaction", false])} 
		&& {((player getVariable ["BTC_need_revive",0]) == 0)} 
		&& {!(_shift)} && {!(_ctrlKey)} && {!(_alt)} && {GVAR(ButtonUp)}
		&& {!(abs((velocity player) select 2) > 20 && (vehicle player == player))}  // this check is the freefall check
		&& {!((vehicle player) isKindOf "ParachuteBase")}) then {
		if (!GVAR(is_open)) then {
			GVAR(ButtonUp) = false;
			_this call FUNC(open);
			GVAR(last_open) = time;
			TRACE_1("Last Open",GVAR(last_open));
			_handled = true;
		} else {
			TRACE_1("Last Open",ARR_3(GVAR(CONFIG_ACTION_BUTTON_TOGGLES),GVAR(last_open),time));
			if (GVAR(CONFIG_ACTION_BUTTON_TOGGLES) != 0) then {
				_handled = _this call FUNC(close);
			};
		};
	};
} else {
	if (GVAR(is_open) && {(_dikCode in actionKeys "Action")}) then {
		[] call FUNC(openSelected);
		_handled = true;
	} else {
		if (_dikCode in actionKeys "GetOver") then {
			GVAR(ButtonUp) = true;
		};
	};
};


TRACE_1("End",_handled);
TMFPROFILERSTOP;
_handled